/**
 *====================================================
 * 文件名称: FinanceEvaluateServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年09月23日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceEvaluateEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.util.DateUtil;

/**
 * @ClassName: FinanceEvaluateServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年09月23日 18:56:17
 */
@Implements(FinanceEvaluateService.class)
public class FinanceEvaluateServiceImpl implements FinanceEvaluateService {

	@Override
	public Long createFinanceEvaluate(FinanceEvaluateEntity entity) {
		entity.setEnabled(Boolean.TRUE);
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
		return entity.getEvaluateId();
	}

	@Override
	public void disableFinanceEvaluate(Long evaluateId) {
		FinanceEvaluateEntity entity = inquireFinanceEvaluate(evaluateId);
		entity.setEnabled(Boolean.FALSE);
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
	}

	@Override
	public FinanceEvaluateEntity inquireFinanceEvaluate(Long evaluateId) {
		return PersistUtil.get(FinanceEvaluateEntity.class, evaluateId);
	}

	@Override
	public FinanceEvaluateEntity inquireFinanceIdEvaluate(Long financeId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceEvaluateEntity.class);
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		criteria.add(Restrictions.eq("financeId", financeId));
		List<FinanceEvaluateEntity> list = PersistUtil.get(criteria);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}

	@Override
	public PageList<FinanceEvaluateEntity> inquireFinanceEvaluatePageList(Long financeId, Long enterpriseId, Long logisticsCompanyId, Boolean enabled, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceEvaluateEntity.class);
		if (enabled != null && enabled.booleanValue()) {
			criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		}
		if (financeId != null) {
			criteria.add(Restrictions.eq("financeId", financeId));
		}
		if (enterpriseId != null) {
			criteria.add(Restrictions.eq("enterpriseId", enterpriseId));
		}
		if (logisticsCompanyId != null) {
			criteria.add(Restrictions.eq("logisticsCompanyId", logisticsCompanyId));
		}
		return PersistUtil.get(criteria, page);
	}

}
